﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Soundteller.Common.Tests
{
    [TestClass]
    public class TestBase
    {
        protected Exception Exception { get; private set; }

        [TestInitialize]
        public virtual void MyTestInitialize()
        {
            Arrange();
            Act();
        }

        [TestCleanup]
        public void MyTestCleanup()
        {
            CleanUp();
        }

        protected virtual void Arrange()
        {
        }

        protected virtual void Act()
        {
        }

        protected virtual void CleanUp()
        {
        }

        protected void ExpectException(Action action)
        {
            try
            {
                action();
            }
            catch (Exception ex)
            {
                Exception = ex;

                return;
            }

            throw new InvalidOperationException("Exception expected! Code runs without exception.");
        }
    }
}